﻿using System;

using NUnit.Framework;

using octalforty.Syndication.Core;
using octalforty.Syndication.Core.Rss;
using octalforty.Syndication.Core.Rss.Aggregators;

namespace octalforty.Syndication.UnitTests.Core.Rss.Aggregators
{
    /// <summary>
    /// <see cref="RssItemAggregator"/> unit tests.
    /// </summary>
    [TestFixture()]
    public class RssItemAggregatorTestFixture : RssAggregatorTestFixtureBase
    {
        [Test()]
        public void Aggregate()
        {
            IAggregator aggregator = new RssItemAggregator();
            ISyndicationFeed syndicationFeed = new RssFeed();

            aggregator.Aggregate(feedDocument, ref syndicationFeed);

            Assert.AreEqual(4, syndicationFeed.Items.Count);

            RssItem rssItem = syndicationFeed.Items[0] as RssItem;

            Assert.IsNotNull(rssItem);
            Assert.AreEqual("Star City", rssItem.Title);
            Assert.AreEqual("http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp", rssItem.Link);
            Assert.AreEqual("How do Americans get ready to work with Russians aboard the International Space Station? " +
                "They take a crash course in culture, language and protocol at Russia's " +
                "<a href=\"http://howe.iki.rssi.ru/GCTC/gctc_e.htm\">Star City</a>.", rssItem.Description);

            Assert.AreEqual(new DateTime(2003, 06, 03, 9, 39, 21),
                rssItem.PublishedOn);
        }

        #region RssAggregatorTestFixtureBase Members
        /// <summary>
        /// When overriden in a derived class, creates an instance of <see cref="IAggregator"/>.
        /// </summary>
        /// <returns></returns>
        protected override IAggregator CreateInstance()
        {
            return new RssItemAggregator();
        }
        #endregion
    }
}
